#include<vector>
using namespace std;

class Solution {
public:
    bool checkSubarraySum(vector<int>& nums, int k) {
        vector<int>sums(nums.size());
        for (int i = 0; i < nums.size(); ++i) {
            sums[i] = nums[i];
            if (i != 0)
                sums[i] += sums[i - 1];
        }

        for (int len = 1; len < nums.size(); ++len) {
            for (int start = 0; start + len < nums.size(); ++start){
                int sum = sums[start + len] - sums[start] + nums[start];
                if (sum == k || (k != 0 && sum % k == 0))
                    return true;
            }

        }
        return false;

    }
};